package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysDomainDAO;
import com.ourteam.system.dao.SysDomain;
import com.ourteam.system.dao.SysDomainDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:35
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysDomainDAOJdbcImpl extends AbstractSpringDAO
    implements ISysDomainDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, DomainCode, DomainIcon, DomainName, DomainTitelKey, Remarks,
            SortIndex, Status, DomainShortName, DomainSmallIcon,
            DomainIconContent, DomainSmallIconContent
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.DomainCode,
            _DataObjectProperty.DomainIcon, _DataObjectProperty.DomainName,
            _DataObjectProperty.DomainTitelKey, _DataObjectProperty.Remarks,
            _DataObjectProperty.SortIndex, _DataObjectProperty.Status,
            _DataObjectProperty.DomainShortName,
            _DataObjectProperty.DomainSmallIcon,
            _DataObjectProperty.DomainIconContent,
            _DataObjectProperty.DomainSmallIconContent
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysDomain, SysDomainDAOQueryBean> daoHelper;

    public AbstractSysDomainDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysDomain, SysDomainDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysDomain
         * @throws Exception
         */
    public boolean checkIsUnique(SysDomain aSysDomain)
        throws Exception {
        if (aSysDomain == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysDomain.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysDomain
     * @throws Exception
     */
    public void insert(SysDomain aSysDomain) throws Exception {
        super.doInsert(aSysDomain);
    }

    /**
         * Batch Insert Datas
         * @param aSysDomain
         * @throws Exception
         */
    public void batchInsert(SysDomain[] aSysDomains) throws Exception {
        super.doBatchInsert(aSysDomains);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysDomainDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysDomain aSysDomain) throws Exception {
        delete(aSysDomain.getId());
    }

    /**
     * Update Data Selective
     * @param aSysDomain
     * @throws Exception
     */
    public void update(SysDomain aSysDomain) throws Exception {
        if (aSysDomain.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysDomain);

        SysDomain tempObj = findById(aSysDomain.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysDomain, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysDomains[]
     * @throws Exception
     */
    public void batchUpdate(SysDomain[] aSysDomains) throws Exception {
        super.doBatchUpdate(aSysDomains);
    }

    /**
         * Update Data By Condictions
         * @param aSysDomain
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysDomain aSysDomain, SysDomainDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aSysDomain, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysDomainDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysDomain aSysDomain)
        throws Exception {
        if (aSysDomain.getDomainIconContent() == null) {
            throw new Exception(
                "The SysDomain.domainIconContent value is not allow NULL");
        }

        if (aSysDomain.getDomainSmallIconContent() == null) {
            throw new Exception(
                "The SysDomain.domainSmallIconContent value is not allow NULL");
        }

        if (aSysDomain.getDomainIcon() == null) {
            throw new Exception(
                "The SysDomain.domainIcon value is not allow NULL");
        }

        if (aSysDomain.getDomainTitelKey() == null) {
            throw new Exception(
                "The SysDomain.domainTitelKey value is not allow NULL");
        }

        if (aSysDomain.getRemarks() == null) {
            throw new Exception("The SysDomain.remarks value is not allow NULL");
        }

        if (aSysDomain.getSortIndex() == null) {
            throw new Exception(
                "The SysDomain.sortIndex value is not allow NULL");
        }

        if (aSysDomain.getStatus() == null) {
            throw new Exception("The SysDomain.status value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysDomain findById(final long id) throws Exception {
        SysDomainDAOQueryBean queryBean = new SysDomainDAOQueryBean();

        SysDomainDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysDomain[] SysDomains = query(queryBean);

        if (SysDomains.length == 0) {
            return null;
        } else {
            return SysDomains[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysDomain[]
         * @throws Exception
         */
    public SysDomain[] query(SysDomainDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean, new JdbcSysDomainRowMapper());

        return (SysDomain[]) result.toArray(new SysDomain[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(SysDomainDAOQueryBean queryBean)
        throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysDomainDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysDomain[] aSysDomains,
        SysDomainDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysDomains, queryBean);
    }

    public void synchronize(SysDomain[] aSysDomains,
        SysDomainDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysDomain> callBack)
        throws Exception {
        daoHelper.synchronize(aSysDomains, queryBean, callBack);
    }

    public static class JdbcSysDomainRowMapper implements RowMapper<SysDomain> {
        public SysDomain mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysDomain object = new SysDomain();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object domainCode = null;

                domainCode = resultSet.getObject(columnIndex++);

                object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

                if (domainCode != null) {
                    setBeanValue(object, _DataObjectProperty.DomainCode,
                        domainCode);
                }

                Object domainIcon = null;

                domainIcon = resultSet.getObject(columnIndex++);

                object.setDomainIconNull(resultSet.getBoolean(columnIndex++));

                if (domainIcon != null) {
                    setBeanValue(object, _DataObjectProperty.DomainIcon,
                        domainIcon);
                }

                Object domainName = null;

                domainName = resultSet.getObject(columnIndex++);

                object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

                if (domainName != null) {
                    setBeanValue(object, _DataObjectProperty.DomainName,
                        domainName);
                }

                Object domainTitelKey = null;

                domainTitelKey = resultSet.getObject(columnIndex++);

                object.setDomainTitelKeyNull(resultSet.getBoolean(columnIndex++));

                if (domainTitelKey != null) {
                    setBeanValue(object, _DataObjectProperty.DomainTitelKey,
                        domainTitelKey);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object sortIndex = null;

                sortIndex = resultSet.getObject(columnIndex++);

                object.setSortIndexNull(resultSet.getBoolean(columnIndex++));

                if (sortIndex != null) {
                    setBeanValue(object, _DataObjectProperty.SortIndex,
                        sortIndex);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object domainShortName = null;

                domainShortName = resultSet.getObject(columnIndex++);

                object.setDomainShortNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (domainShortName != null) {
                    setBeanValue(object, _DataObjectProperty.DomainShortName,
                        domainShortName);
                }

                Object domainSmallIcon = null;

                domainSmallIcon = resultSet.getObject(columnIndex++);

                object.setDomainSmallIconNull(resultSet.getBoolean(
                        columnIndex++));

                if (domainSmallIcon != null) {
                    setBeanValue(object, _DataObjectProperty.DomainSmallIcon,
                        domainSmallIcon);
                }

                Object domainIconContent = null;

                domainIconContent = resultSet.getObject(columnIndex++);

                object.setDomainIconContentNull(resultSet.getBoolean(
                        columnIndex++));

                if (domainIconContent != null) {
                    setBeanValue(object, _DataObjectProperty.DomainIconContent,
                        domainIconContent);
                }

                Object domainSmallIconContent = null;

                domainSmallIconContent = resultSet.getObject(columnIndex++);

                object.setDomainSmallIconContentNull(resultSet.getBoolean(
                        columnIndex++));

                if (domainSmallIconContent != null) {
                    setBeanValue(object,
                        _DataObjectProperty.DomainSmallIconContent,
                        domainSmallIconContent);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
